<template>
	<view class="container">
		<uni-section title="食物轮播图展示" type="line"></uni-section>
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="(item,index) in swipers">

				<image :src="'http://localhost:8090'+item.icon" :mode="item.icon"  style="width: 100%;height: 180px;"></image>

			</swiper-item>
		</swiper>

		<uni-section title="食物类别宫格展示" type="line"></uni-section>
		<uni-grid :column="3">
			<uni-grid-item v-for="(item,index) in grids">
				<view class="" 
				style="display: flex;
					flex-direction: column;align-items: center;
				   justify-content: center;flex: 1;">
					<image :src="'http://localhost:8090'+item.icon" mode="" style="width: 75px;height: 75px;"></image>
					<view class="">
						{{item.typename}}
					</view>
				</view>
			</uni-grid-item>
		</uni-grid>

		<uni-section title="食物列表展示(4条)" type="line"></uni-section>
		
		
		<uni-list>
			<uni-list-item v-for="(item,index) in foods" clickable @click="foodsOne(item.id)" :title="item.name" :thumb="'http://localhost:8090'+item.icon" :rightText="'￥'+item.price+'元'"></uni-list-item>
		</uni-list>
		
		<uni-section title="食物评论列表展示(2条)" type="line"></uni-section>
		<uni-list>
			<navigator url="../../comment/commentlist/commentlist" open-type="switchTab">
			<uni-list-item v-for="(item,index) in comments"  :title="item.comment" :rightText="item.postdate"></uni-list-item>
			</navigator>
		</uni-list>
	</view>
</template>

<script>
import fooddetailVue from '../fooddetail/fooddetail.vue';
	export default {
		data() {
			return {
				swipers: [
					{}
				],
				grids: [
					{}
				],
				foods:[
					{}
				],
				comments:[
					{}
				]
			}
		},
		methods: {
			foodsOne(id){
				uni.navigateTo({
					url:"../fooddetail/fooddetail?id="+id
				})
			}
		}
		
		,
		
		onLoad() {
			//轮播图
			uni.request({
				url: 'http://localhost:8090/foodapp/foodSwiper/list',
				method: 'POST',
				data: {},
				success: res => {
					if (res.data.success) {
						this.swipers = res.data.list
						uni.showToast({
							title: '成功',
							icon: 'none'
						});
					} else {
						uni.showToast({
							title: '失败',
							icon: 'none'
						});
					}
				},
				fail: () => {
					uni.showToast({
						title: '失败',
						icon: 'none'
					});
				},
				complete: () => {}
			});
			//宫格图
			uni.request({
				url: 'http://localhost:8090/foodapp/foodType/list',
				method: 'POST',
				data: {},
				success: res => {
					if (res.data.success) {
						this.grids = res.data.list

						uni.showToast({
							title: '成功',
							icon: 'none'
						});
					} else {
						uni.showToast({
							title: '失败',
							icon: 'none'
						});
					}
				},
				fail: () => {
					uni.showToast({
						title: '失败',
						icon: 'none'
					});
				},
				complete: () => {}
			});
			//食物列表
			uni.request({
				url: 'http://localhost:8090/foodapp/food/list',
				method: 'POST',
				data: {},
				success: res => {
					if (res.data.success) {
						this.foods = res.data.list
						uni.showToast({
							title: '成功',
							icon: 'none'
						});
					} else {
						uni.showToast({
							title: '失败',
							icon: 'none'
						});
					}
				},
				fail: () => {
					uni.showToast({
						title: '失败',
						icon: 'none'
					});
				},
				complete: () => {}
			});
			// 评论列表
			uni.request({
				url: 'http://localhost:8090/foodapp/comment/list',
				method: 'POST',
				data: {},
				success: res => {
					if (res.data.success) {
						this.comments = res.data.list
						uni.showToast({
							title: '成功',
							icon: 'none'
						});
					} else {
						uni.showToast({
							title: '失败',
							icon: 'none'
						});
					}
				},
				fail: () => {
					uni.showToast({
						title: '失败',
						icon: 'none'
					});
				},
				complete: () => {}
			});
		}
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}
</style>